package com.sacc.controller;

import com.power.common.model.CommonResult;
import com.sacc.pojo.Infographic;
import com.sacc.service.Impl.InfographicServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;


/**
 * @author 滚~韬
 * @date 2022/4/4 18:57
 */
@RestController
@RequestMapping("/news/infographic")
public class InfographicController {
    @Autowired
    private InfographicServiceImpl infographicService;
    @PostMapping("/upload")
    private CommonResult InfographicUpload(MultipartFile file,Integer state){
        try
        {
            return infographicService.Upload(file,state);
        }catch (Exception e){
            return new CommonResult("400","插入失败:"+e.toString());
        }
    }
    @Deprecated
    @PostMapping("/uploads")
    private CommonResult InfographicUploads(MultipartFile[] files){
        try
        {
            infographicService.Upload(files);
            return new CommonResult("200","插入成功");
        }catch (Exception e){
            return new CommonResult("400","插入失败:"+e.toString());
        }

    }
    @Deprecated
    @PostMapping("/deletebyurl")
    private CommonResult InfographicDelete(@RequestParam String url){
        try{
            return infographicService.Delete(url);
        }
        catch (Exception e){
            return new CommonResult("400","插入失败:"+e.toString());
        }
    }
    @PostMapping("/deletebyid")
    private CommonResult InfographicDelete(@RequestParam Integer id){
        try{
            return  infographicService.Delete(id);
        }
        catch (Exception e){
            return new CommonResult("400","插入失败:"+e.toString());
        }
    }
    @GetMapping("/getlist")
    private List<Infographic> InfographicGet(@RequestParam Integer state){
        return infographicService.GetAll(state);
    }
}
